/*
    jME Task Framework, for executing tasks in a Java/OpenGL enviroment
    Copyright (C) 2005-2006,  Tijl Houtbeckers
    
    **** LICENSE: ****

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation,
	version 2.1.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

	**** CONTACT: ****

    I can be reached through the jmonkeyengine.com forums (user "llama"), 
    or the jmonkeyengine.com contact page:
    jmonkeyengine.com/index.php?option=com_contact&task=view&contact_id=5           

*/

/**
 * @author Tijl Houtbeckers
 */

package org.llama.jmex.task;

public abstract class TaskRunner {
	
	public abstract int reserveTask();
	public abstract void cancelReserveTask(int id);
	
	public abstract void assign(Task task, int id);
	
	public abstract void prepareRun(Task task);
	
	public abstract void resume(Task task);
	public abstract boolean isPausable();
	public abstract void pause(Task task);
	public abstract boolean isPaused(Task task);
	
	public abstract void removeTask(Task task);
	
	public abstract Task[] getTasks();
	
	protected boolean runTask(Task task) {
		try {
			return task.runTaskFromRunner();
		} catch (Throwable t) {
			t.printStackTrace();
			task.complete();
			return true;
		}
	}
	
	protected static final Task RESERVED = new Task() {
		public void updatePriority() {
		}
		public boolean runTask() {
			return true;
		}
		public Object identifier() {
			return null;
		}
		
	};
	

}
